import { defineStore } from 'pinia'

export const useInviteStore = defineStore(
  'invite',
  () => {
    const inviteList = ref([])

    const push = (id: any, invitationCode: any) => {
      let inviteItem = inviteList.value.find((item) => item.id === id)
      if (inviteItem) {
        inviteItem.invitationCode = invitationCode
      } else {
        inviteList.value.push({ id, invitationCode })
      }
    }

    const fineInviteCode = (id: any) => {
      let inviteItem = inviteList.value.find((item) => item.id == id)
      if (inviteItem) {
        return inviteItem.invitationCode || ''
      } else {
        return ''
      }
    }

    return {
      inviteList,
      push,
      fineInviteCode,
    }
  },
  {
    persist: true,
  },
)
